package com.xh.rufongwallpaper.common.exception;

import com.xh.rufongwallpaper.common.result.ResultCode;
import lombok.Getter;

/**
 * API业务异常
 *
 * @author XH
 */
@Getter
public class ApiException extends RuntimeException {

    /**
     * 错误代码
     */
    private final Integer code;

    /**
     * 错误消息
     */
    private final String message;

    /**
     * 构造方法
     *
     * @param message 错误消息
     */
    public ApiException(String message) {
        super(message);
        this.code = ResultCode.FAILURE.getCode();
        this.message = message;
    }

    /**
     * 构造方法
     *
     * @param code    错误代码
     * @param message 错误消息
     */
    public ApiException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * 构造方法
     *
     * @param resultCode 结果代码
     */
    public ApiException(ResultCode resultCode) {
        super(resultCode.getMessage());
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    /**
     * 构造方法
     *
     * @param resultCode 结果代码
     * @param message    错误消息
     */
    public ApiException(ResultCode resultCode, String message) {
        super(message);
        this.code = resultCode.getCode();
        this.message = message;
    }
}